{layout name="layout" /}
{load href="/static/js/laydate/laydate.js" /}
<div class="row">
    <div id="back_div" class="row m-t-xs" style ="position:relative;bottom: 0px;width:100%;background-color: white ;margin-left:0px;margin-right:0px;" >
    <div class="col-xs-12 text-center" style="vertical-align: central;">
        <a href="{:merge_url('plan/plan_detail');} " class="pull-left"  style='color: #286090;font-size:2rem;'>
            <span  class="glyphicon glyphicon-chevron-left"></span>
        </a>
    </div>
</div>
<div class="col-xs-12 col-md-4 col-md-offset-4">        
    <form class="form-horizontal col-xs-12"  action="{:url('');}"  method="post">
        <div class="form-group">
           <input name="id" type="hidden" class="form-control" id="input_id" value="{$one.id|default='无'}">
            <label for="input_plan_str" class="cos-xs-3 control-label">目标名称</label>
            <div class="cos-xs-9">
                <input name="plan_str" type="text" class="form-control" id="input_plan_str" placeholder="目标名称" value="{$one.plan_str|default='无'}">
            </div>
        </div>
        <div class="form-group">
            <label for="plan_time_id" class="cos-xs-3 control-label">计划完成日期</label>
            <div class="cos-xs-9">
                <input id="plan_time_id" name="plan_time" type="text" class="form-control layui-input"  
                       placeholder="yyyy年MM月dd日" lay-key="12" value="{$one.plan_time|default=time()|to_date='Y-m-d'}">
            </div>
        </div>
        <div class="form-group">
            <label for="cycle" class="cos-xs-3 control-label">周期</label>
            <div class="cos-xs-9">
                <select id="cycle" name="cycle"  class="form-control">
                    <option value="0" {eq name="one.cycle" value="0"}selected {/eq}>不循环</option>
                    <option value="1" {eq name="one.cycle" value="1"}selected {/eq}>每天</option>
                    <option value="7" {eq name="one.cycle" value="7"}selected {/eq}>每周</option>
                    <!--<option value="30" >每月</option>-->
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="cos-xs-offset-3 cos-xs-6 m-t-sm" >
                <button id="submit" type="submit" class="btn btn-default pull-left" style="width: 40%;margin-left: 5%" >更新</button>
                <button id="delete" type="submit" class="btn btn-default pull-right" style="width: 40%;margin-right: 5%" >删除</button>
            </div>
        </div>
    </form>
</div>
</div>
<script>
    $ (function ()
    {
        laydate.render({
            elem: '#plan_time_id'
            ,format: 'yyyy-MM-dd'
        });
        
        $("#captcha").on('click',function()
        {
           let img_src = $(this).attr('src')+"?seed="+Math.random; 
           $(this).attr('src',img_src);
        });
        
        function error_layer (msg)
        {
            layer.open ({
                content: msg,
                btn: '关闭',
                yes: function ()
                {
                    layer.closeAll ();
                }
            });
        }

        function success_layer (msg)
        {
            layer.open ({
                content: msg,
                btn: '关闭',
                yes: function ()
                {
                    layer.closeAll ();
                    location.href = "{:merge_url('plan/plan_list')}";
                }
            });
        }

        $ ("#submit").on ('click', function (eve)
        {
            eve.preventDefault ();
            let url = $ ('form').attr ('action');
            let data = $('form').serialize();
            $.post (url, data, function (res)
            {
                if (res.code)
                {
                    success_layer(res.msg);
                }
                else
                {
                    error_layer(res.msg);
                }
            });
        });
        
        $ ("#delete").on ('click', function (eve)
        {
            eve.preventDefault ();
            let url = "{:merge_url('plan/delete_plan');}";
            let data = $('form').serialize();
            $.post (url, data, function (res)
            {
                if (res.code)
                {
                    success_layer(res.msg);
                }
                else
                {
                    error_layer(res.msg);
                }
            });
        });
    });

</script>